// JS错误日志，继承于日志基类MonitorBaseInfo
function ResourceLoadErrorInfo() {

    this.handleLogInfo = function (logMsg) {
        delete this.handleLogInfo;


        var data = {
            ...getCommonProperty(),
            uploadType: 'RESOURCE_LOAD_ERR',
            logMsg: logMsg
        }
        new Image().src = "http://log.besteasylearn.com/log.gif?appKey=123&json=" + JSON.stringify(data)
        
        var res = $.post({
            url: "/log/up",
            data: data,
            async: false
        });
        console.log(res.responseJSON, "=========responseJSON========")


        console.log(logMsg, "======resErrorInfo.handleLogInfo.logMsg=======")
    }
}


/**
   * 监控页面静态资源加载报错
   */
function recordResourceError() {
    // 当浏览器不支持 window.performance.getEntries 的时候，用下边这种方式
    window.addEventListener('error', function (e) {
        var typeName = e.target.localName;
        var sourceUrl = "";
        if (typeName === "link") {
            sourceUrl = e.target.href;
        } else if (typeName === "script") {
            sourceUrl = e.target.src;
        }

        if (sourceUrl.length == 0) {
            return;
        }
        var resErrorInfo = new ResourceLoadErrorInfo();
        resErrorInfo.handleLogInfo({
            sourceUrl: sourceUrl,
            typeName
        });
    }, true);
}


recordResourceError()

